package com.xiangyang.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;
import java.util.UUID;

public class JwtUtil {

    private static final String sign = "your-secret-key";

    public static String CreateToken(String subject, long time) {
        String jwtToken = Jwts.builder()
                .setHeaderParam("alg", "HS256")
                .setSubject(subject)
                .setExpiration(new Date(System.currentTimeMillis() + time))
                .setId(UUID.randomUUID().toString())
                .signWith(SignatureAlgorithm.HS256, sign.getBytes())
                .compact();
        return jwtToken;
    }

    public static Claims parseJwt(String token) {
        Claims claims = Jwts.parser()
                .setSigningKey(sign.getBytes())
                .parseClaimsJws(token)
                .getBody();
        return claims;
    }
    }